﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtils;

/// <summary>
/// 该页面对应着功能说明书的查看工资记录页。
/// </summary>
public partial class Salary_DefaultQuery : System.Web.UI.Page
{
    DataSet dsResult;
    /// <summary>
    /// 网页初始化时执行该方法。设置控件属性
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtStartTime.Text = "2000-01-01";
            txtEndTime.Text = "2010-01-01";
        }
        Label3.Visible = false;
        btnPrint.Visible = false;
    }

    /// <summary>
    /// 当用户单击“搜索”按钮时，该方法将根据用户指定的条件，搜索数据库中相应的数据，并用 DataGrid 控件显示结果。
    /// 该过程调用 SalaryInfo.QueryHistorySalary(CInt(Session("EmployeeID")), txtStartTime.Text.Trim, txtEndTime.Text.Trim, dsResult) 函数，
    /// 根据用户设定的搜索条件，搜索登录员工在该阶段内的工资信息。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        dsResult = new DataSet();
        if (SalaryInfo.QueryHistorySalary(Convert.ToInt32(Session["EmployeeID"]), txtStartTime.Text.Trim(), txtEndTime.Text.Trim(), ref dsResult) == 1)
        {
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                Label3.Visible = true;
            }
            grdResult.DataSource = dsResult.Tables[0];
            grdResult.DataBind();
            grdResult.Visible = true;
        }
        else
        {
            this.Response.Write("<script>alert('" + "查询信息失败" + "');</script>");//弹出失败信息
        }
    }

    /// <summary>
    /// 当用户单击选中 DataGrid 控件中的某条记录时，该方法将使“打印工资单”按钮可见。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grdResult_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnPrint.Visible = true;
    }

    /// <summary>
    /// 当用户单击“打印工资单”按钮时，该方法打开一个新的浏览器窗口来显示工资单。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        Employee emp=new Employee();
        Employee.GetEmployeeInfo(Convert.ToInt32(Session["EmployeeID"]),emp);



        this.Response.Write("<script>window.open('Print.aspx?name=" + emp.Name + "&dept=" + emp.DeptName + "&month=" + Convert.ToDateTime(grdResult.SelectedRow.Cells[0].Text).Month.ToString() + "&basic=" + grdResult.SelectedRow.Cells[1].Text + "&overtime=" + grdResult.SelectedRow.Cells[2].Text + "&absenct=" + grdResult.SelectedRow.Cells[3].Text + "&other=" + grdResult.SelectedRow.Cells[4].Text + "&actural=" + grdResult.SelectedRow.Cells[5].Text + "')</script>");
    }
}
